<HTML><HEAD> <!-- ---------- The Tailor ---------- --> <SCRIPT LANGUAGE="JavaScript"><!-- hide from old browsers /* THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com Copyright (c)2000 by Charles River Media. All Rights Reserved. This applet can only be re-used or modifed by license holders of the JavaScript Cookbook CD-ROM. Credit must be given in the source code and this copyright notice must be maintained. If you do not hold a license to the JavaScript Cookbook, you may NOT duplicate or modify this code for your own use. Use at your own risk. No warranty is given or implied of the suitability of this applet for any specific application. Neither Erica Sadun nor Charles River Media will be held responsible for any unwanted effects due to the use of this applet or any derivative. */ // --------------------Formulas--------------------- // Guess my sizes from the data entered on the form function sizeme(aform) { var t = "" var waist = parseInt(aform.WAIST.value) var weight = parseInt(aform.WEIGHT.value) // Hat Size a = (""+((5.0 * (weight / waist)) / 2.125)) b = a.lastIndexOf(".") if (b > 0) a = a.substring(0,b+2) t += "Hat-Size: "+a+"; " // Neck Size a = (""+(3.0 * (weight / waist))) b = a.lastIndexOf(".") if (b > 0) a = a.substring(0,b+2) t += "Neck-Size: "+a+"; " // Arm Length a = (""+(waist / 2)) b = a.lastIndexOf(".") if (b > 0) a = a.substring(0,b+2) t += "Arm-Length: "+a+"; " // Shoe Size a = (""+(45.0 * (waist / weight))) b = a.lastIndexOf(".") if (b > 0) a = a.substring(0,b+2) t += "Shoe-Size: "+a aform.SIZES.value = t aform.WAIST.focus() aform.WAIST.select() } <!-- done hiding --></SCRIPT></HEAD> <BODY bgcolor="ffffff" onLoad="document.forms[0].WAIST.focus();"+ "document.forms[0].WAIST.select();return true"> <FONT COLOR="007777"><H1><IMG SRC="../GRAFX/UTENS.JPG" WIDTH=80 HEIGHT=50 ALIGN = CENTER>The JavaScript Tailor</H1></FONT> <BLOCKQUOTE> <FONT COLOR="770000"> This JavaScript Applet will attempt to guess a man's measurements from his weight and waistline. </FONT> <FONT SIZE=4> <FORM><PRE> Waistline: <INPUT TYPE="text" SIZE="10" NAME="WAIST"> Weight: <INPUT TYPE="text" SIZE="10" NAME="WEIGHT"> <INPUT TYPE="button" VALUE="Guess Sizes" onClick="sizeme(this.form);return true"> <TEXTAREA WRAP=PHYSICAL NAME="SIZES" ROWS=3 COLS=35> </TEXTAREA></PRE></FORM> </FONT></BLOCKQUOTE> <FONT COLOR="007777"><H2>Discussion</H2></FONT> <FONT SIZE=4> This example makes extensive use of JavaScript mathematical formulas. For example, this script guesses a man's hat size to be approximately five times his weight (in pounds) divided by his waist (in inches) divided again by two and an eighth. In JavaScript, this formula looks like this. <pre><FONT COLOR="770000" SIZE=3>(5.0 * (weight / waist)) / 2.125</pre></FONT> Always be careful to check your formulas carefully and make sure that your parentheses match. Assure your functions have open and close brackets and are commented liberally. Test your formulas out on some known examples and try to make sure that they work in advance. </FONT> <p><FONT SIZE=2><b>Note:</b> This example was inspired by the writings of Doug Cooper and Michael Clancy. </FONT> <h5>Copyright ©1996 by Charles River Media, All Rights Reserved</h5> </BODY> </HTML>